1
'*************************** Module Header ******************************'
2 ' Module Name: MainModule.vb
3 ' Project: VBApplicationToCrash
4 ' Copyright (c) Microsoft Corporation.
6 ' When this application starts, it will launch a Watchdog process. It will also
7 ' create an unhandled exception.
9 ' This source is subject to the Microsoft Public License.
10 ' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 ' All other rights reserved.
13 ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
14 ' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
15 ' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
16 '*************************************************************************'
18 Imports System
.Runtime
.InteropServices
23 Dim demoProcess
As Process
= Process
.GetCurrentProcess()
24 Console
.WriteLine("The ID of this Demo Process is " & demoProcess
.Id
)
26 LaunchWatchdog(demoProcess
)
28 ' Wait 2 seconds, so the watch dog process can attach a debugger to this
30 System
.Threading
.Thread
.Sleep(2000)
32 Console
.WriteLine("Press ENTER to throw an unhandled exception...")
36 Dim zero
As Integer = 0
38 ' This exception will be handled by the catch block, so the watch dog
39 ' will not create a minidump at this moment.
40 Console
.WriteLine(1 \ zero
)
44 Console
.WriteLine(ex
.GetType())
46 ' Rethrowing the exception will cause an unhandled exception, and the watch
47 ' dog will create a minidump now.
54 ''' Launch the Watchdog process.
56 ''' <param name="demoProcess"></param>
57 Sub LaunchWatchdog(ByVal demoProcess
As Process
)
59 Console
.WriteLine("Launch Watchdog process...")
60 Dim start
As ProcessStartInfo
= New ProcessStartInfo
With _
61 {.Arguments
= demoProcess
.Id
.ToString(),
62 .FileName
= "VBCreateMiniDump.exe"}
63 Dim miniDumpCreatorProcess
As Process
= Process
.Start(start
)
64 Console
.WriteLine("The Watchdog process was launched!")
66 Console
.WriteLine("The Watchdog process was not launched!")
67 Console
.WriteLine(ex
.Message
)